package com.mob.tools.utils;

import android.text.TextUtils;
import com.mob.tools.MobLog;
import com.mob.tools.log.NLog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Hashon
{
  private ArrayList<?> arrayToList(Object paramObject)
  {
    Object localObject;
    if ((paramObject instanceof byte[]))
    {
      localObject = new ArrayList();
      byte[] arrayOfByte = (byte[])paramObject;
      int i = arrayOfByte.length;
      for (int j = 0; j < i; j++)
        ((ArrayList)localObject).add(Byte.valueOf(arrayOfByte[j]));
    }
    if ((paramObject instanceof short[]))
    {
      ArrayList localArrayList1 = new ArrayList();
      short[] arrayOfShort = (short[])paramObject;
      int k = arrayOfShort.length;
      for (int m = 0; m < k; m++)
        localArrayList1.add(Short.valueOf(arrayOfShort[m]));
      localObject = localArrayList1;
      return localObject;
    }
    if ((paramObject instanceof int[]))
    {
      ArrayList localArrayList2 = new ArrayList();
      int[] arrayOfInt = (int[])paramObject;
      int n = arrayOfInt.length;
      for (int i1 = 0; i1 < n; i1++)
        localArrayList2.add(Integer.valueOf(arrayOfInt[i1]));
      return localArrayList2;
    }
    if ((paramObject instanceof long[]))
    {
      ArrayList localArrayList3 = new ArrayList();
      long[] arrayOfLong = (long[])paramObject;
      int i2 = arrayOfLong.length;
      for (int i3 = 0; i3 < i2; i3++)
        localArrayList3.add(Long.valueOf(arrayOfLong[i3]));
      return localArrayList3;
    }
    if ((paramObject instanceof float[]))
    {
      ArrayList localArrayList4 = new ArrayList();
      float[] arrayOfFloat = (float[])paramObject;
      int i4 = arrayOfFloat.length;
      for (int i5 = 0; i5 < i4; i5++)
        localArrayList4.add(Float.valueOf(arrayOfFloat[i5]));
      return localArrayList4;
    }
    if ((paramObject instanceof double[]))
    {
      ArrayList localArrayList5 = new ArrayList();
      double[] arrayOfDouble = (double[])paramObject;
      int i6 = arrayOfDouble.length;
      for (int i7 = 0; i7 < i6; i7++)
        localArrayList5.add(Double.valueOf(arrayOfDouble[i7]));
      return localArrayList5;
    }
    if ((paramObject instanceof char[]))
    {
      ArrayList localArrayList6 = new ArrayList();
      char[] arrayOfChar = (char[])paramObject;
      int i8 = arrayOfChar.length;
      for (int i9 = 0; i9 < i8; i9++)
        localArrayList6.add(Character.valueOf(arrayOfChar[i9]));
      return localArrayList6;
    }
    if ((paramObject instanceof boolean[]))
    {
      ArrayList localArrayList7 = new ArrayList();
      boolean[] arrayOfBoolean = (boolean[])paramObject;
      int i10 = arrayOfBoolean.length;
      for (int i11 = 0; i11 < i10; i11++)
        localArrayList7.add(Boolean.valueOf(arrayOfBoolean[i11]));
      return localArrayList7;
    }
    if ((paramObject instanceof String[]))
    {
      ArrayList localArrayList8 = new ArrayList();
      String[] arrayOfString = (String[])paramObject;
      int i12 = arrayOfString.length;
      for (int i13 = 0; i13 < i12; i13++)
        localArrayList8.add(arrayOfString[i13]);
      return localArrayList8;
    }
    return null;
  }

  private String format(String paramString, ArrayList<Object> paramArrayList)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("[\n");
    String str = paramString + "\t";
    int i = 0;
    Iterator localIterator = paramArrayList.iterator();
    if (localIterator.hasNext())
    {
      Object localObject = localIterator.next();
      if (i > 0)
        localStringBuffer.append(",\n");
      localStringBuffer.append(str);
      if ((localObject instanceof HashMap))
        localStringBuffer.append(format(str, (HashMap)localObject));
      while (true)
      {
        i++;
        break;
        if ((localObject instanceof ArrayList))
          localStringBuffer.append(format(str, (ArrayList)localObject));
        else if ((localObject instanceof String))
          localStringBuffer.append('"').append(localObject).append('"');
        else
          localStringBuffer.append(localObject);
      }
    }
    localStringBuffer.append('\n').append(paramString).append(']');
    return localStringBuffer.toString();
  }

  private String format(String paramString, HashMap<String, Object> paramHashMap)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("{\n");
    String str = paramString + "\t";
    int i = 0;
    Iterator localIterator = paramHashMap.entrySet().iterator();
    if (localIterator.hasNext())
    {
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      if (i > 0)
        localStringBuffer.append(",\n");
      localStringBuffer.append(str).append('"').append((String)localEntry.getKey()).append("\":");
      Object localObject = localEntry.getValue();
      if ((localObject instanceof HashMap))
        localStringBuffer.append(format(str, (HashMap)localObject));
      while (true)
      {
        i++;
        break;
        if ((localObject instanceof ArrayList))
          localStringBuffer.append(format(str, (ArrayList)localObject));
        else if ((localObject instanceof String))
          localStringBuffer.append('"').append(localObject).append('"');
        else
          localStringBuffer.append(localObject);
      }
    }
    localStringBuffer.append('\n').append(paramString).append('}');
    return localStringBuffer.toString();
  }

  private ArrayList<Object> fromJson(JSONArray paramJSONArray)
    throws JSONException
  {
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    int j = paramJSONArray.length();
    if (i < j)
    {
      Object localObject = paramJSONArray.opt(i);
      if ((localObject instanceof JSONObject))
        localObject = fromJson((JSONObject)localObject);
      while (true)
      {
        localArrayList.add(localObject);
        i++;
        break;
        if ((localObject instanceof JSONArray))
          localObject = fromJson((JSONArray)localObject);
      }
    }
    return localArrayList;
  }

  private <T> HashMap<String, T> fromJson(JSONObject paramJSONObject)
    throws JSONException
  {
    HashMap localHashMap = new HashMap();
    Iterator localIterator = paramJSONObject.keys();
    while (localIterator.hasNext())
    {
      String str = (String)localIterator.next();
      Object localObject = paramJSONObject.opt(str);
      if (JSONObject.NULL.equals(localObject))
        localObject = null;
      if (localObject != null)
      {
        if ((localObject instanceof JSONObject))
          localObject = fromJson((JSONObject)localObject);
        while (true)
        {
          localHashMap.put(str, localObject);
          break;
          if ((localObject instanceof JSONArray))
            localObject = fromJson((JSONArray)localObject);
        }
      }
    }
    return localHashMap;
  }

  private JSONArray getJSONArray(ArrayList<Object> paramArrayList)
    throws JSONException
  {
    JSONArray localJSONArray = new JSONArray();
    Iterator localIterator = paramArrayList.iterator();
    if (localIterator.hasNext())
    {
      Object localObject = localIterator.next();
      if ((localObject instanceof HashMap))
        localObject = getJSONObject((HashMap)localObject);
      while (true)
      {
        localJSONArray.put(localObject);
        break;
        if ((localObject instanceof ArrayList))
          localObject = getJSONArray((ArrayList)localObject);
      }
    }
    return localJSONArray;
  }

  private <T> JSONObject getJSONObject(HashMap<String, T> paramHashMap)
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    Iterator localIterator = paramHashMap.entrySet().iterator();
    if (localIterator.hasNext())
    {
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      Object localObject = localEntry.getValue();
      if ((localObject instanceof HashMap))
        localObject = getJSONObject((HashMap)localObject);
      while (true)
      {
        localJSONObject.put((String)localEntry.getKey(), localObject);
        break;
        if ((localObject instanceof ArrayList))
          localObject = getJSONArray((ArrayList)localObject);
        else if (isBasicArray(localObject))
          localObject = getJSONArray(arrayToList(localObject));
      }
    }
    return localJSONObject;
  }

  private boolean isBasicArray(Object paramObject)
  {
    return ((paramObject instanceof byte[])) || ((paramObject instanceof short[])) || ((paramObject instanceof int[])) || ((paramObject instanceof long[])) || ((paramObject instanceof float[])) || ((paramObject instanceof double[])) || ((paramObject instanceof char[])) || ((paramObject instanceof boolean[])) || ((paramObject instanceof String[]));
  }

  public String format(String paramString)
  {
    try
    {
      String str = format("", fromJson(paramString));
      return str;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return "";
  }

  public <T> String fromHashMap(HashMap<String, T> paramHashMap)
  {
    try
    {
      JSONObject localJSONObject = getJSONObject(paramHashMap);
      if (localJSONObject == null)
        return "";
      String str = localJSONObject.toString();
      return str;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return "";
  }

  public <T> HashMap<String, T> fromJson(String paramString)
  {
    if (TextUtils.isEmpty(paramString))
      return new HashMap();
    try
    {
      if ((paramString.startsWith("[")) && (paramString.endsWith("]")))
        paramString = "{\"fakelist\":" + paramString + "}";
      HashMap localHashMap = fromJson(new JSONObject(paramString));
      return localHashMap;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(paramString, new Object[0]);
      MobLog.getInstance().w(localThrowable);
    }
    return new HashMap();
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.tools.utils.Hashon
 * JD-Core Version:    0.6.2
 */